# Load Necessary Packages
library(tidyverse)
library(estimatr)
library(psych)
library(glmnet)
library(plotrix)
library(lme4)
library(sjPlot)
library(stargazer)
library(mgcv)
library(fixest)
library(marginaleffects)
library(cocor)
library(ggridges)

# Load Dataset
setwd("/users/josephphillips/Dropbox/Projects/Protesters in Our Heads/Data/Data")
data <- read.csv("PiOH_March2025_Values1.csv",header=T,sep=",")

# Code Variables
## Pre-Treatment Perceived Composition of Protesters
data$men_protest_pre <- data$Gender_Protest_Pre_1
data$women_protest_pre <- data$Gender_Protest_Pre_2
data$trans_protest_pre <- data$Gender_Protest_Pre_3
data$othergender_protest_pre <- data$Gender_Protest_Pre_5
data$white_protest_pre <- data$Race_Protest_Pre_1
data$black_protest_pre <- data$Race_Protest_Pre_2
data$asian_protest_pre <- data$Race_Protest_Pre_3
data$hispanic_protest_pre <- data$Race_Protest_Pre_4
data$otherrace_protest_pre <- data$Race_Protest_Pre_5
data$straight_protest_pre <- data$LGB_Protest_Pre_1
data$gay_protest_pre <- data$LGB_Protest_Pre_2
data$othersexuality_protest_pre <- data$LGB_Protest_Pre_3
data$conservative_protest_pre <- data$Ideo_Protest_Pre_1
data$liberal_protest_pre <- data$Ideo_Protest_Pre_2
data$moderate_protest_pre <- data$Ideo_Protest_Pre_3
data$otherideology_protest_pre <- data$Ideo_Protest_Pre_4
data$republican_protest_pre <- data$Party_Protest_Pre_1
data$democratic_protest_pre <- data$Party_Protest_Pre_2
data$independent_protest_pre <- data$Party_Protest_Pre_3
data$otherparty_protest_pre <- data$Party_Protest_Pre_4
data$evangelical_protest_pre <- data$Religion_Protest_Pre_1
data$otherchristian_protest_pre <- data$Religion_Protest_Pre_2
data$jewish_protest_pre <- data$Religion_Protest_Pre_3
data$muslim_protest_pre <- data$Religion_Protest_Pre_4
data$atheist_protest_pre <- data$Religion_Protest_Pre_5
data$otherreligion_protest_pre <- data$Religion_Protest_Pre_6
data$urban_protest_pre <- data$Place_Protest_Pre_1
data$suburban_protest_pre <- data$Place_Protest_Pre_2
data$rural_protest_pre <- data$Place_Protest_Pre_3
data$union_protest_pre <- data$Union_Protest_Pre_1
data$nonunion_protest_pre <- data$Union_Protest_Pre_2
data$poor_protest_pre <- data$Income_Protest_Pre_1
data$rich_protest_pre <- data$Income_Protest_Pre_2
data$otherincome_protest_pre <- data$Income_Protest_Pre_3
data$degree_protest_pre <- data$Edu_Protest_Pre_1
data$dropout_protest_pre <- data$Edu_Protest_Pre_2
data$somecollege_protest_pre <- data$Edu_Protest_Pre_4
## Post-Treatment Perceived Composition of Protesters
data$men_protest_post <- data$Gender_Protest_Post_1
data$women_protest_post <- data$Gender_Protest_Post_2
data$trans_protest_post <- data$Gender_Protest_Post_3
data$othergender_protest_post <- data$Gender_Protest_Post_5
data$white_protest_post <- data$Race_Protest_Post_1
data$black_protest_post <- data$Race_Protest_Post_2
data$asian_protest_post <- data$Race_Protest_Post_3
data$hispanic_protest_post <- data$Race_Protest_Post_4
data$otherrace_protest_post <- data$Race_Protest_Post_5
data$straight_protest_post <- data$LGB_Protest_Post_1
data$gay_protest_post <- data$LGB_Protest_Post_2
data$othersexuality_protest_post <- data$LGB_Protest_Post_3
data$conservative_protest_post <- data$Ideo_Protest_Post_1
data$liberal_protest_post <- data$Ideo_Protest_Post_2
data$moderate_protest_post <- data$Ideo_Protest_Post_3
data$otherideology_protest_post <- data$Ideo_Protest_Post_4
data$republican_protest_post <- data$Party_Protest_Post_1
data$democratic_protest_post <- data$Party_Protest_Post_2
data$independent_protest_post <- data$Party_Protest_Post_3
data$otherparty_protest_post <- data$Party_Protest_Post_4
data$evangelical_protest_post <- data$Religion_Protest_Pos_1
data$otherchristian_protest_post <- data$Religion_Protest_Pos_2
data$jewish_protest_post <- data$Religion_Protest_Pos_3
data$muslim_protest_post <- data$Religion_Protest_Pos_4
data$atheist_protest_post <- data$Religion_Protest_Pos_5
data$otherreligion_protest_post <- data$Religion_Protest_Pos_6
data$urban_protest_post <- data$Place_Protest_Post_1
data$suburban_protest_post <- data$Place_Protest_Post_2
data$rural_protest_post <- data$Place_Protest_Post_3
data$union_protest_post <- data$Union_Protest_Post_1
data$nonunion_protest_post <- data$Union_Protest_Post_2
data$poor_protest_post <- data$Income_Protest_Post_1
data$rich_protest_post <- data$Income_Protest_Post_2
data$otherincome_protest_post <- data$Income_Protest_Post_3
data$degree_protest_post <- data$Edu_Protest_Post_1
data$dropout_protest_post <- data$Edu_Protest_Post_2
data$somecollege_protest_post <- data$Edu_Protest_Post_4
## Pre-Treatment Attitudes Toward Protest
data$protest1_pre <- (data$Pre_Pro_Impt-1)/4
data$protest2_pre <- (data$Pre_Pro_Laws-1)/4
data$protest3_pre <- (data$Pre_Pro_Permit_Laws-1)/4
data$protest4_pre <- (5-data$Pre_Pro_Arrest)/4
data$protest5_pre <- (5-data$Pre_Pro_Strict)/4
data$protest6_pre <- (5-data$Pre_Pro_Stop)/4
data$protest7_pre <- data$Pre_Pro_FT_1/100
psych::alpha(cbind.data.frame(data$protest1_pre,data$protest2_pre,data$protest3_pre,data$protest4_pre,data$protest5_pre,data$protest6_pre,data$protest7_pre)) # alpha=.83
data$protest_pre <- (data$protest1_pre+data$protest2_pre+data$protest3_pre+data$protest4_pre+data$protest5_pre+data$protest6_pre+data$protest7_pre)/7
## Post-Treatment Attitudes Toward Protest
data$protest1_post <- (data$Post_Pro_Impt-1)/4
data$protest2_post <- (data$Post_Pro_Laws-9)/4
data$protest3_post <- (data$Post_Pro_Permit_Laws-1)/4
data$protest4_post <- (5-data$Post_Pro_Arrest)/4
data$protest5_post <- (5-data$Post_Pro_Strict)/4
data$protest6_post <- (5-data$Post_Pro_Stop)/4
data$protest7_post <- data$Post_Pro_FT_1/100
psych::alpha(cbind.data.frame(data$protest1_post,data$protest2_post,data$protest3_post,data$protest4_post,data$protest5_post,data$protest6_post,data$protest7_post)) # alpha=.84
data$protest_post <- (data$protest1_post+data$protest2_post+data$protest3_post+data$protest4_post+data$protest5_post+data$protest6_post+data$protest7_post)/7
## Gender (Gender)
data$female <- ifelse(data$Gender==17,1,0)
data$nonbinary <- ifelse(data$Gender==18,1,0)
## Race (Race)
data$white <- ifelse(as.numeric(as.factor(data$Race))==2 | as.numeric(as.factor(data$Race))==3 | as.numeric(as.factor(data$Race))==4 | as.numeric(as.factor(data$Race))==5 | as.numeric(as.factor(data$Race))==6 | as.numeric(as.factor(data$Race))==7 | as.numeric(as.factor(data$Race))==8 | as.numeric(as.factor(data$Race))==9,1,0)
data$black <- ifelse(as.numeric(as.factor(data$Race))==3 | as.numeric(as.factor(data$Race))==4 | as.numeric(as.factor(data$Race))==10 | as.numeric(as.factor(data$Race))==11 | as.numeric(as.factor(data$Race))==12 | as.numeric(as.factor(data$Race))==13,1,0)
data$indigenous <- ifelse(as.numeric(as.factor(data$Race))==4 | as.numeric(as.factor(data$Race))==5 | as.numeric(as.factor(data$Race))==6 | as.numeric(as.factor(data$Race))==11 | as.numeric(as.factor(data$Race))==14 | as.numeric(as.factor(data$Race))==15,1,0)
data$asian <- ifelse(as.numeric(as.factor(data$Race))==6 | as.numeric(as.factor(data$Race))==7 | as.numeric(as.factor(data$Race))==8 | as.numeric(as.factor(data$Race))==12 | as.numeric(as.factor(data$Race))==16,1,0)
data$pacific <- ifelse(as.numeric(as.factor(data$Race))==17,1,0)
data$othrace <- ifelse(as.numeric(as.factor(data$Race))==9 | as.numeric(as.factor(data$Race))==13 | as.numeric(as.factor(data$Race))==15 | as.numeric(as.factor(data$Race))==18,1,0)
## Ethnicity (Ethnicity)
data$hispanic <- ifelse(data$Ethnicity==1,1,0)
## Education (Educ, no changes needed)
## Income (income)
data$inc_000 <- ifelse(data$income==1,0,ifelse(data$income==2,35,ifelse(data$income==3,70,ifelse(data$income==4,100,ifelse(data$income==5,150,ifelse(data$income==6,200,ifelse(data$income==7,250,NA)))))))
## Religion (Religion)
data$catholic <- ifelse(data$Religion==2,1,0)
data$orthodox <- ifelse(data$Religion==3,1,0)
data$mormon <- ifelse(data$Religion==4,1,0)
data$jewish <- ifelse(data$Religion==5,1,0)
data$muslim <- ifelse(data$Religion==6,1,0)
data$buddhist <- ifelse(data$Religion==7,1,0)
data$hindu <- ifelse(data$Religion==8,1,0)
data$atheist <- ifelse(data$Religion==9,1,0)
data$agnostic <- ifelse(data$Religion==10,1,0)
data$othreligion <- ifelse(data$Religion==11,1,0)
data$noreligion <- ifelse(data$Religion==12,1,0)
## Evangelical (Evangelical)
data$evangelical_christian <- ifelse(data$Evangelical==1,1,0)
## Age (Age)
data$age <- 2025-data$Age
## Urbanity (Place)
data$suburban <- ifelse(data$Place==2,1,0)
data$townie <- ifelse(data$Place==3,1,0)
data$rural <- ifelse(data$Place==4,1,0)
data$othplace <- ifelse(data$Place==5,1,0)
## Ideology (ideology)
data$conservatism <- (data$ideology-1)/6
## Party (Party, pidstrength, Party.Leaners)
data$pid <- NA
data$pid[data$Party==1 & data$pidstrength==1] <- 1
data$pid[data$Party==1 & data$pidstrength==2] <- 2
data$pid[(data$Party==2 | data$Party==4) & data$Party.Leaners==2] <- 3
data$pid[(data$Party==2 | data$Party==4) & data$Party.Leaners==3] <- 4
data$pid[(data$Party==2 | data$Party==4) & data$Party.Leaners==1] <- 5
data$pid[data$Party==3 & data$pidstrength==2] <- 6
data$pid[data$Party==3 & data$pidstrength==1] <- 7
## Political Interest (interest)
data$polinterest <- (4-data$interest)/3
## Self-Monitoring Scale (Monitor1, Monitor2, Monitor3)
data$selfmonitor_1 <- (5-data$Monitor1)/4
data$selfmonitor_2 <- (5-data$Monitor2)/4
data$selfmonitor_3 <- (5-data$Monitor3)/4
psych::alpha(cbind.data.frame(data$selfmonitor_1,data$selfmonitor_2,data$selfmonitor_3)) # alpha=.56
data$selfmonitor <- (data$selfmonitor_1+data$selfmonitor_2+data$selfmonitor_3)/3
## Attitudes Toward Partisan Violence (KM1_R, KM2_R, KM3_R, KM1_D, KM2_D, KM_D3)
data$km1_rep <- (data$KM1_R-1)/3
data$km2_rep <- (data$KM2_R-1)/3
data$km3_rep <- (data$KM3_R-1)/4
data$km1_dem <- (data$KM1_D-1)/3
data$km2_dem <- (data$KM2_D-1)/3
data$km3_dem <- (data$KM_D3-1)/4
data$km1 <- ifelse(data$pid<4,data$km1_dem,ifelse(data$pid>4,data$km1_rep,NA))
data$km2 <- ifelse(data$pid<4,data$km2_dem,ifelse(data$pid>4,data$km2_rep,NA))
data$km3 <- ifelse(data$pid<4,data$km3_dem,ifelse(data$pid>4,data$km3_rep,NA))
psych::alpha(cbind.data.frame(data$km1,data$km2,data$km3)) # alpha=.87
data$km <- (data$km1+data$km2+data$km3)/3
## Attitudes Toward Political Violence (PV1, PV2, PV3)
data$polvol_1 <- (data$PV1-1)/4
data$polvol_2 <- (data$PV2-1)/4
data$polvol_3 <- (data$PV3-1)/4
psych::alpha(cbind.data.frame(data$polvol_1,data$polvol_2,data$polvol_3)) # alpha=.81
data$polvol <- (data$polvol_1+data$polvol_2+data$polvol_3)/3
## Attitudes Toward Political Violence (Composite)
psych::alpha(cbind.data.frame(data$km1,data$km2,data$km3,data$polvol_1,data$polvol_2,data$polvol_3))
data$polvol_composite <- (data$km1+data$km2+data$km3+data$polvol_1+data$polvol_2+data$polvol_3)/6
## Attitudes Toward Democratic norms (Norms1, Norms2, Norms3, Norms4)
data$demnorms_1 <- (5-data$Norms1)/4
data$demnorms_2 <- (data$Norms2-1)/4
data$demnorms_3 <- (data$Norms3-1)/4
data$demnorms_4 <- (5-data$Norms4)/4
psych::alpha(cbind.data.frame(data$demnorms_1,data$demnorms_2,data$demnorms_3,data$demnorms_4)) # alpha=.61
data$demnorms <- (data$demnorms_1+data$demnorms_2+data$demnorms_3+data$demnorms_4)/4
## Experimental Condition
data$control_condition <- ifelse(is.na(data$FMC_control)==F,1,0)
data$info_treatment <- ifelse(is.na(data$Info_FMC_1)==F | is.na(data$Info_FMC_2)==F | is.na(data$Info_FMC_3)==F | is.na(data$Info_FMC_4)==F,1,0)
data$blm_treatment <- ifelse(is.na(data$FMC_BLM_1)==F | is.na(data$FMC_BLM_2)==F | is.na(data$FMC_BLM_3)==F | is.na(data$FMC_BLM_4)==F,1,0)
data$j6_treatment <- ifelse(is.na(data$J6_FMC_1)==F | is.na(data$J6_FMC_2)==F | is.na(data$J6_FMC_3)==F | is.na(data$J6_FMC_4)==F,1,0)
# Separate Data into All and Attentive-Only
## Code Attention Check Passage (Attention1, FMC_control, FMC_BLM, J6_FMC, Info_FMC)
data$attention1_pass <- ifelse(data$Attention1==11,1,0)
data$control_pass <- ifelse(data$control_condition==1 & data$FMC_control==1905,1,ifelse(data$control_condition==1 & data$FMC_control!=1905,0,NA))
data$info_pass_1 <- ifelse(data$Info_FMC_1>=35 & data$Info_FMC_1<=55,1,0)
data$info_pass_2 <- ifelse(data$Info_FMC_2>=8 & data$Info_FMC_2<=28,1,0)
data$info_pass_3 <- ifelse(data$Info_FMC_3<=14,1,0)
data$info_pass_4 <- ifelse(data$Info_FMC_4>=54 & data$Info_FMC_4<=74,1,0)
data$info_pass <- ifelse((data$info_pass_1+data$info_pass_2+data$info_pass_3+data$info_pass_4)>=3,1,0)
data$blm_pass_1 <- ifelse(data$FMC_BLM_1>=30 & data$FMC_BLM_1<=50,1,0)
data$blm_pass_2 <- ifelse(data$FMC_BLM_2<=20,1,0)
data$blm_pass_3 <- ifelse(data$FMC_BLM_3<=16,1,0)
data$blm_pass_4 <- ifelse(data$FMC_BLM_4>=54 & data$FMC_BLM_4<=74,1,0)
data$blm_pass <- ifelse((data$blm_pass_1+data$blm_pass_2+data$blm_pass_3+data$blm_pass_4)>=3,1,0)
data$j6_pass_1 <- ifelse(data$J6_FMC_1>=76 & data$J6_FMC_1<=96,1,0)
data$j6_pass_2 <- ifelse(data$J6_FMC_2>=26 & data$J6_FMC_3<=46,1,0)
data$j6_pass_3 <- ifelse(data$J6_FMC_3>=14 & data$J6_FMC_4<=34,1,0)
data$j6_pass_4 <- ifelse(data$J6_FMC_4<=11,1,0)
data$j6_pass <- ifelse((data$j6_pass_1+data$j6_pass_2+data$j6_pass_3+data$j6_pass_4)>=3,1,0)
data$posttreatment_pass <- ifelse(is.na(data$control_pass)==F,data$control_pass,ifelse(is.na(data$info_pass)==F,data$info_pass,ifelse(is.na(data$blm_pass)==F,data$blm_pass,ifelse(is.na(data$j6_pass)==F,data$j6_pass,NA))))
## Split Data
data.attentive <- subset(data,control_pass==1 | info_pass==1 | blm_pass==1 | j6_pass==1)
data.dem <- subset(data,pid<4)
data.rep <- subset(data,pid>4)
data.attentive.dem <- subset(data.attentive,pid<4)
data.attentive.rep <- subset(data.attentive,pid>4)
data.ind <- subset(data,pid==4)
# Lasso Analyses
## Lasso Command
run_LASSO <- function(data, yvar, pre){
  
  set.seed(2334)
  
  var_quo <- enquo(yvar)
  var_quo1 <- enquo(pre)
  
  ## select x variables 
  dat <- data %>%
    dplyr::select(female, nonbinary, black, indigenous, asian, pacific, othrace, hispanic, inc_000, catholic, orthodox, mormon, jewish, muslim, buddhist, hindu, atheist, agnostic, othreligion, noreligion, evangelical_christian, age, suburban, townie, rural, othplace, conservatism, pid, polinterest, selfmonitor)
  
  pre <- data %>%
    dplyr::select(!!var_quo1) %>% pull() # Save as a vector instead of a data frame ot use model matrix
  
  ## select y-variable
  out1 <- data %>% 
    dplyr::select(!!var_quo) %>% pull() # save as a vector instead of a data-frame to use model.matrix()
  
  merged1 <- cbind(out1, dat, pre) %>% na.omit() ## merge and delete NA
  x1 <- model.matrix(out1 ~ ., data = merged1) ## make model matrix
  y1 <- merged1$out1 ## select y-variable from NA-deleted dataset
  mod1 <- cv.glmnet(x1, y1, alpha = 1, family = "gaussian") ## run lasso model
  coef <- coef(mod1) ## get coef  
  
  list(merged1, x1, y1, mod1, coef)
  
}

run_LASSO_nopre <- function(data, yvar){
  
  set.seed(2334)
  
  var_quo <- enquo(yvar)
  
  ## select x variables 
  dat <- data %>%
    dplyr::select(female, nonbinary, black, indigenous, asian, pacific, othrace, hispanic, inc_000, catholic, orthodox, mormon, jewish, muslim, buddhist, hindu, atheist, agnostic, othreligion, noreligion, evangelical_christian, age, suburban, townie, rural, othplace, conservatism, pid, polinterest, selfmonitor)
  
  ## select y-variable
  out1 <- data %>% 
    dplyr::select(!!var_quo) %>% pull() # save as a vector instead of a data-frame to use model.matrix()
  
  merged1 <- cbind(out1, dat) %>% na.omit() ## merge and delete NA
  x1 <- model.matrix(out1 ~ ., data = merged1) ## make model matrix
  y1 <- merged1$out1 ## select y-variable from NA-deleted dataset
  mod1 <- cv.glmnet(x1, y1, alpha = 1, family = "gaussian") ## run lasso model
  coef <- coef(mod1) ## get coef  
  
  list(merged1, x1, y1, mod1, coef)
  
}
## Lasso Analyses on Each DV, All Respondents
protest_lasso_all <- run_LASSO(data,protest_post,protest_pre) # pre
polvol_lasso_all <- run_LASSO_nopre(data,polvol_composite) # age, selfmonitor
demnorms_lasso_all <- run_LASSO_nopre(data,demnorms) # black, evangelical_christian, age, conservatism, pid, polinterest, selfmonitor
## Lasso Analyses on Each DV, Attentive Respondents Only
protest_lasso_attentive <- run_LASSO(data.attentive,protest_post,protest_pre) # pre
polvol_lasso_attentive <- run_LASSO_nopre(data.attentive,polvol_composite) # none
demnorms_lasso_attentive <- run_LASSO_nopre(data.attentive,demnorms) # age, conservatism, pid, polinterest, selfmonitor
## Democrats, All
protest_lasso_dem <- run_LASSO(data.dem,protest_post,protest_pre) # pre
polvol_lasso_dem <- run_LASSO_nopre(data.dem,polvol_composite) # age, conservatism, selfmonitor
demnorms_lasso_dem <- run_LASSO_nopre(data.dem,demnorms) # black, catholic, orthodox, muslim, evangelical_christian, age, rural, conservatism, pid, polinterest, selfmonitor
## Republicans, All
protest_lasso_rep <- run_LASSO(data.rep,protest_post,protest_pre) # pre
polvol_lasso_rep <- run_LASSO_nopre(data.rep,polvol_composite) # none
demnorms_lasso_rep <- run_LASSO_nopre(data.rep,demnorms) # none

# Descriptives About DVs in Text
## Protest
mean(data$protest_pre,na.rm=T) # Mean=0.64
sd(data$protest_pre,na.rm=T) # SD=0.21
## Democratic Norms
mean(data$demnorms,na.rm=T) # Mean=.0.75
sd(data$demnorms,na.rm=T) # SD=0.18
## Political Violence
mean(data$polvol_composite,na.rm=T) # Mean=0.14
sd(data$polvol_composite,na.rm=T) # SD=0.19

# Figure 1
f1data <- data.frame(Outcome=factor(c(rep("Protest",4),rep("Democratic Norms",4),rep("Political Violence",4)),levels=c("Political Violence","Democratic Norms","Protest")),
                     Sample=factor(c("All","Attentive","Dem","Rep","All","Attentive","Dem","Rep","All","Attentive","Dem","Rep"),levels=c("Rep","Dem","Attentive","All")),
                     level=c(mean(data$protest_post,na.rm=T),mean(data.attentive$protest_post,na.rm=T),mean(data.dem$protest_post,na.rm=T),mean(data.rep$protest_post,na.rm=T),mean(data$demnorms,na.rm=T),mean(data.attentive$demnorms,na.rm=T),mean(data.dem$demnorms,na.rm=T),mean(data.rep$demnorms,na.rm=T),mean(data$polvol_composite,na.rm=T),mean(data.attentive$polvol_composite,na.rm=T),mean(data.dem$polvol_composite,na.rm=T),mean(data.rep$polvol_composite,na.rm=T)),
                     se=c(std.error(data$protest_post,na.rm=T),std.error(data.attentive$protest_post,na.rm=T),std.error(data.dem$protest_post,na.rm=T),std.error(data.rep$protest_post,na.rm=T),std.error(data$demnorms,na.rm=T),std.error(data.attentive$demnorms,na.rm=T),std.error(data.dem$demnorms,na.rm=T),std.error(data.rep$demnorms,na.rm=T),std.error(data$polvol_composite,na.rm=T),std.error(data.attentive$polvol_composite,na.rm=T),std.error(data.dem$polvol_composite,na.rm=T),std.error(data.rep$polvol_composite,na.rm=T)))
f1data$lci <- f1data$level-(1.96*f1data$se)
f1data$uci <- f1data$level+(1.96*f1data$se)
f1 <- ggplot(f1data,aes(x=Outcome,y=level,group=Sample,color=Sample)) + geom_point(position=position_dodge(0.6)) + theme_classic() + coord_flip() + geom_errorbar(aes(ymin=lci,ymax=uci),lwd=0.5,width=0,position=position_dodge(0.6)) + geom_hline(yintercept=0.5,linetype="dashed",color="red") + scale_color_manual(values=c("Red","Blue","Gray50","Black"),guide = guide_legend(reverse = TRUE)) + theme(legend.position="bottom") + ylim(0,1)

# Correlations Between DVs in Text
cor.test(data$protest_post,data$demnorms) # r=.49, p<.001
cor.test(data$protest_post,data$polvol_composite) # r=.13, p<.001
cor.test(data$demnorms,data$polvol_composite) # r=-.20, p<.001

# Figure 2
## Underlying Models
m.protest <- lm_robust(protest_post~info_treatment+blm_treatment+j6_treatment+protest_pre,data=data)
m.protest.attentive <- lm_robust(protest_post~info_treatment+blm_treatment+j6_treatment+protest_pre,data=data.attentive)
m.protest.dem <- lm_robust(protest_post~info_treatment+blm_treatment+j6_treatment+protest_pre,data=data.dem)
m.protest.rep <- lm_robust(protest_post~info_treatment+blm_treatment+j6_treatment+protest_pre,data=data.rep)
m.demnorms <- lm_robust(demnorms~info_treatment+blm_treatment+j6_treatment+black+evangelical_christian+age+conservatism+pid+polinterest+selfmonitor,data=data)
m.demnorms.attentive <- lm_robust(demnorms~info_treatment+blm_treatment+j6_treatment+age+conservatism+pid+polinterest+selfmonitor,data=data.attentive)
m.demnorms.dem <- lm_robust(demnorms~info_treatment+blm_treatment+j6_treatment+black+catholic+orthodox+muslim+evangelical_christian+age+rural+conservatism+pid+polinterest+selfmonitor,data=data.dem)
m.demnorms.nocov.rep <- lm_robust(demnorms~info_treatment+blm_treatment+j6_treatment,data=data.rep)
m.polvolcomposite <- lm_robust(polvol_composite~info_treatment+blm_treatment+j6_treatment+age+selfmonitor,data=data)
m.polvolcomposite.attentive <- lm_robust(polvol_composite~info_treatment+blm_treatment+j6_treatment,data=data)
m.polvolcomposite.dem <- lm_robust(polvol_composite~info_treatment+blm_treatment+j6_treatment+conservatism+age+selfmonitor,data=data)
m.polvolcomposite.rep <- lm_robust(polvol_composite~info_treatment+blm_treatment+j6_treatment,data=data)
## Figure
plotdata.experimentbyparty <- data.frame(outcome=factor(c(rep("Protest",12),rep("Democratic Norms",12),rep("Political Violence",12)),levels=c("Protest","Democratic Norms","Political Violence")),
                                         Condition=factor(c(rep(c("Correction","BLM","Jan 6"),12)),levels=c("Jan 6","BLM","Correction")),
                                         Sample=factor(c(rep(c("All","All","All","Attentive","Attentive","Attentive","Dem","Dem","Dem","Rep","Rep","Rep"),3)),levels=c("Rep","Dem","Attentive","All")),
                                         Effect=c(m.protest$coefficients[2:4],m.protest.attentive$coefficients[2:4],m.protest.dem$coefficients[2:4],m.protest.rep$coefficients[2:4],m.demnorms$coefficients[2:4],m.demnorms.attentive$coefficients[2:4],m.demnorms.dem$coefficients[2:4],m.demnorms.nocov.rep$coefficients[2:4],m.polvolcomposite$coefficients[2:4],m.polvolcomposite.attentive$coefficients[2:4],m.polvolcomposite.dem$coefficients[2:4],m.polvolcomposite.rep$coefficients[2:4]),
                                         lci=c(m.protest$conf.low[2:4],m.protest.attentive$conf.low[2:4],m.protest.dem$conf.low[2:4],m.protest.rep$conf.low[2:4],m.demnorms$conf.low[2:4],m.demnorms.attentive$conf.low[2:4],m.demnorms.dem$conf.low[2:4],m.demnorms.nocov.rep$conf.low[2:4],m.polvolcomposite$conf.low[2:4],m.polvolcomposite.attentive$conf.low[2:4],m.polvolcomposite.dem$conf.low[2:4],m.polvolcomposite.rep$conf.low[2:4]),
                                         uci=c(m.protest$conf.high[2:4],m.protest.attentive$conf.high[2:4],m.protest.dem$conf.high[2:4],m.protest.rep$conf.high[2:4],m.demnorms$conf.high[2:4],m.demnorms.attentive$conf.high[2:4],m.demnorms.dem$conf.high[2:4],m.demnorms.nocov.rep$conf.high[2:4],m.polvolcomposite$conf.high[2:4],m.polvolcomposite.attentive$conf.high[2:4],m.polvolcomposite.dem$conf.high[2:4],m.polvolcomposite.rep$conf.high[2:4]))

p.experiment.byparty <- ggplot(plotdata.experimentbyparty,aes(x=Condition,y=Effect,group=Sample,color=Sample)) + geom_point(position=position_dodge(0.9)) + theme_classic() + coord_flip() + geom_hline(yintercept=0,linetype="dashed",color="red") + geom_errorbar(aes(ymin=lci,ymax=uci),lwd=0.5,width=0,position=position_dodge(0.9)) + scale_color_manual(values=c("Red","Blue","Grey50","Black"),guide = guide_legend(reverse = TRUE)) + ylab("Effect") + ylab("Effect") + facet_wrap(vars(outcome),nrow=2,ncol=2) + theme(legend.position="bottom")

# Figure 3
## Underlying Models
data$protest_post100 <- data$protest_post*100
data$protest1_post100 <- data$protest1_post*100
data$protest2_post100 <- data$protest2_post*100
data$protest3_post100 <- data$protest3_post*100
data$protest4_post100 <- data$protest4_post*100
data$protest5_post100 <- data$protest5_post*100
data$protest6_post100 <- data$protest6_post*100
data$protest7_post100 <- data$protest7_post*100
data$demnorm100 <- data$demnorms*100
data$demnorm1_100 <- data$demnorms_1*100
data$demnorm2_100 <- data$demnorms_2*100
data$demnorm3_100 <- data$demnorms_3*100
data$demnorm4_100 <- data$demnorms_4*100
data$polvol100 <- data$polvol_composite*100
data$polvol1_100 <- data$km1*100
data$polvol2_100 <- data$km2*100
data$polvol3_100 <- data$km3*100
data$polvol4_100 <- data$polvol_1*100
data$polvol5_100 <- data$polvol_2*100
data$polvol6_100 <- data$polvol_3*100
m.rq2.post.l <- lm(protest_post100~women_protest_pre+trans_protest_pre+othergender_protest_pre+black_protest_pre+hispanic_protest_pre+asian_protest_pre+otherrace_protest_pre+gay_protest_pre+othersexuality_protest_pre+conservative_protest_pre+liberal_protest_pre+otherideology_protest_pre+republican_protest_pre+democratic_protest_pre+otherparty_protest_pre+evangelical_protest_pre+jewish_protest_pre+muslim_protest_pre+atheist_protest_pre+otherreligion_protest_pre+urban_protest_pre+rural_protest_pre+union_protest_pre+poor_protest_pre+rich_protest_pre+degree_protest_pre+dropout_protest_pre+female+nonbinary+black+indigenous+asian+pacific+othrace+hispanic+inc_000+catholic+orthodox+mormon+jewish+muslim+buddhist+hindu+atheist+agnostic+othreligion+noreligion+evangelical_christian+age+suburban+townie+rural+othplace+conservatism+pid+polinterest+selfmonitor+info_treatment+blm_treatment+j6_treatment,data=data)
m.rq2.post.1.l <- lm(protest1_post100~women_protest_pre+trans_protest_pre+othergender_protest_pre+black_protest_pre+hispanic_protest_pre+asian_protest_pre+otherrace_protest_pre+gay_protest_pre+othersexuality_protest_pre+conservative_protest_pre+liberal_protest_pre+otherideology_protest_pre+republican_protest_pre+democratic_protest_pre+otherparty_protest_pre+evangelical_protest_pre+jewish_protest_pre+muslim_protest_pre+atheist_protest_pre+otherreligion_protest_pre+urban_protest_pre+rural_protest_pre+union_protest_pre+poor_protest_pre+rich_protest_pre+degree_protest_pre+dropout_protest_pre+female+nonbinary+black+indigenous+asian+pacific+othrace+hispanic+inc_000+catholic+orthodox+mormon+jewish+muslim+buddhist+hindu+atheist+agnostic+othreligion+noreligion+evangelical_christian+age+suburban+townie+rural+othplace+conservatism+pid+polinterest+selfmonitor+info_treatment+blm_treatment+j6_treatment,data=data)
m.rq2.post.2.l <- lm(protest2_post100~women_protest_pre+trans_protest_pre+othergender_protest_pre+black_protest_pre+hispanic_protest_pre+asian_protest_pre+otherrace_protest_pre+gay_protest_pre+othersexuality_protest_pre+conservative_protest_pre+liberal_protest_pre+otherideology_protest_pre+republican_protest_pre+democratic_protest_pre+otherparty_protest_pre+evangelical_protest_pre+jewish_protest_pre+muslim_protest_pre+atheist_protest_pre+otherreligion_protest_pre+urban_protest_pre+rural_protest_pre+union_protest_pre+poor_protest_pre+rich_protest_pre+degree_protest_pre+dropout_protest_pre+female+nonbinary+black+indigenous+asian+pacific+othrace+hispanic+inc_000+catholic+orthodox+mormon+jewish+muslim+buddhist+hindu+atheist+agnostic+othreligion+noreligion+evangelical_christian+age+suburban+townie+rural+othplace+conservatism+pid+polinterest+selfmonitor+info_treatment+blm_treatment+j6_treatment,data=data)
m.rq2.post.3.l <- lm(protest3_post100~women_protest_pre+trans_protest_pre+othergender_protest_pre+black_protest_pre+hispanic_protest_pre+asian_protest_pre+otherrace_protest_pre+gay_protest_pre+othersexuality_protest_pre+conservative_protest_pre+liberal_protest_pre+otherideology_protest_pre+republican_protest_pre+democratic_protest_pre+otherparty_protest_pre+evangelical_protest_pre+jewish_protest_pre+muslim_protest_pre+atheist_protest_pre+otherreligion_protest_pre+urban_protest_pre+rural_protest_pre+union_protest_pre+poor_protest_pre+rich_protest_pre+degree_protest_pre+dropout_protest_pre+female+nonbinary+black+indigenous+asian+pacific+othrace+hispanic+inc_000+catholic+orthodox+mormon+jewish+muslim+buddhist+hindu+atheist+agnostic+othreligion+noreligion+evangelical_christian+age+suburban+townie+rural+othplace+conservatism+pid+polinterest+selfmonitor+info_treatment+blm_treatment+j6_treatment,data=data)
m.rq2.post.4.l <- lm(protest4_post100~women_protest_pre+trans_protest_pre+othergender_protest_pre+black_protest_pre+hispanic_protest_pre+asian_protest_pre+otherrace_protest_pre+gay_protest_pre+othersexuality_protest_pre+conservative_protest_pre+liberal_protest_pre+otherideology_protest_pre+republican_protest_pre+democratic_protest_pre+otherparty_protest_pre+evangelical_protest_pre+jewish_protest_pre+muslim_protest_pre+atheist_protest_pre+otherreligion_protest_pre+urban_protest_pre+rural_protest_pre+union_protest_pre+poor_protest_pre+rich_protest_pre+degree_protest_pre+dropout_protest_pre+female+nonbinary+black+indigenous+asian+pacific+othrace+hispanic+inc_000+catholic+orthodox+mormon+jewish+muslim+buddhist+hindu+atheist+agnostic+othreligion+noreligion+evangelical_christian+age+suburban+townie+rural+othplace+conservatism+pid+polinterest+selfmonitor+info_treatment+blm_treatment+j6_treatment,data=data)
m.rq2.post.5.l <- lm(protest5_post100~women_protest_pre+trans_protest_pre+othergender_protest_pre+black_protest_pre+hispanic_protest_pre+asian_protest_pre+otherrace_protest_pre+gay_protest_pre+othersexuality_protest_pre+conservative_protest_pre+liberal_protest_pre+otherideology_protest_pre+republican_protest_pre+democratic_protest_pre+otherparty_protest_pre+evangelical_protest_pre+jewish_protest_pre+muslim_protest_pre+atheist_protest_pre+otherreligion_protest_pre+urban_protest_pre+rural_protest_pre+union_protest_pre+poor_protest_pre+rich_protest_pre+degree_protest_pre+dropout_protest_pre+female+nonbinary+black+indigenous+asian+pacific+othrace+hispanic+inc_000+catholic+orthodox+mormon+jewish+muslim+buddhist+hindu+atheist+agnostic+othreligion+noreligion+evangelical_christian+age+suburban+townie+rural+othplace+conservatism+pid+polinterest+selfmonitor+info_treatment+blm_treatment+j6_treatment,data=data)
m.rq2.post.6.l <- lm(protest6_post100~women_protest_pre+trans_protest_pre+othergender_protest_pre+black_protest_pre+hispanic_protest_pre+asian_protest_pre+otherrace_protest_pre+gay_protest_pre+othersexuality_protest_pre+conservative_protest_pre+liberal_protest_pre+otherideology_protest_pre+republican_protest_pre+democratic_protest_pre+otherparty_protest_pre+evangelical_protest_pre+jewish_protest_pre+muslim_protest_pre+atheist_protest_pre+otherreligion_protest_pre+urban_protest_pre+rural_protest_pre+union_protest_pre+poor_protest_pre+rich_protest_pre+degree_protest_pre+dropout_protest_pre+female+nonbinary+black+indigenous+asian+pacific+othrace+hispanic+inc_000+catholic+orthodox+mormon+jewish+muslim+buddhist+hindu+atheist+agnostic+othreligion+noreligion+evangelical_christian+age+suburban+townie+rural+othplace+conservatism+pid+polinterest+selfmonitor+info_treatment+blm_treatment+j6_treatment,data=data)
m.rq2.post.7.l <- lm(protest7_post100~women_protest_pre+trans_protest_pre+othergender_protest_pre+black_protest_pre+hispanic_protest_pre+asian_protest_pre+otherrace_protest_pre+gay_protest_pre+othersexuality_protest_pre+conservative_protest_pre+liberal_protest_pre+otherideology_protest_pre+republican_protest_pre+democratic_protest_pre+otherparty_protest_pre+evangelical_protest_pre+jewish_protest_pre+muslim_protest_pre+atheist_protest_pre+otherreligion_protest_pre+urban_protest_pre+rural_protest_pre+union_protest_pre+poor_protest_pre+rich_protest_pre+degree_protest_pre+dropout_protest_pre+female+nonbinary+black+indigenous+asian+pacific+othrace+hispanic+inc_000+catholic+orthodox+mormon+jewish+muslim+buddhist+hindu+atheist+agnostic+othreligion+noreligion+evangelical_christian+age+suburban+townie+rural+othplace+conservatism+pid+polinterest+selfmonitor+info_treatment+blm_treatment+j6_treatment,data=data)
m.cor.dnorm.l <- lm(demnorm100~women_protest_pre+trans_protest_pre+othergender_protest_pre+black_protest_pre+hispanic_protest_pre+asian_protest_pre+otherrace_protest_pre+gay_protest_pre+othersexuality_protest_pre+conservative_protest_pre+liberal_protest_pre+otherideology_protest_pre+republican_protest_pre+democratic_protest_pre+otherparty_protest_pre+evangelical_protest_pre+jewish_protest_pre+muslim_protest_pre+atheist_protest_pre+otherreligion_protest_pre+urban_protest_pre+rural_protest_pre+union_protest_pre+poor_protest_pre+rich_protest_pre+degree_protest_pre+dropout_protest_pre+female+nonbinary+black+indigenous+asian+pacific+othrace+hispanic+inc_000+catholic+orthodox+mormon+jewish+muslim+buddhist+hindu+atheist+agnostic+othreligion+noreligion+evangelical_christian+age+suburban+townie+rural+othplace+conservatism+pid+polinterest+selfmonitor+info_treatment+blm_treatment+j6_treatment,data=data)
m.cor.dnorm1.l <- lm(demnorm1_100~women_protest_pre+trans_protest_pre+othergender_protest_pre+black_protest_pre+hispanic_protest_pre+asian_protest_pre+otherrace_protest_pre+gay_protest_pre+othersexuality_protest_pre+conservative_protest_pre+liberal_protest_pre+otherideology_protest_pre+republican_protest_pre+democratic_protest_pre+otherparty_protest_pre+evangelical_protest_pre+jewish_protest_pre+muslim_protest_pre+atheist_protest_pre+otherreligion_protest_pre+urban_protest_pre+rural_protest_pre+union_protest_pre+poor_protest_pre+rich_protest_pre+degree_protest_pre+dropout_protest_pre+female+nonbinary+black+indigenous+asian+pacific+othrace+hispanic+inc_000+catholic+orthodox+mormon+jewish+muslim+buddhist+hindu+atheist+agnostic+othreligion+noreligion+evangelical_christian+age+suburban+townie+rural+othplace+conservatism+pid+polinterest+selfmonitor+info_treatment+blm_treatment+j6_treatment,data=data)
m.cor.dnorm2.l <- lm(demnorm2_100~women_protest_pre+trans_protest_pre+othergender_protest_pre+black_protest_pre+hispanic_protest_pre+asian_protest_pre+otherrace_protest_pre+gay_protest_pre+othersexuality_protest_pre+conservative_protest_pre+liberal_protest_pre+otherideology_protest_pre+republican_protest_pre+democratic_protest_pre+otherparty_protest_pre+evangelical_protest_pre+jewish_protest_pre+muslim_protest_pre+atheist_protest_pre+otherreligion_protest_pre+urban_protest_pre+rural_protest_pre+union_protest_pre+poor_protest_pre+rich_protest_pre+degree_protest_pre+dropout_protest_pre+female+nonbinary+black+indigenous+asian+pacific+othrace+hispanic+inc_000+catholic+orthodox+mormon+jewish+muslim+buddhist+hindu+atheist+agnostic+othreligion+noreligion+evangelical_christian+age+suburban+townie+rural+othplace+conservatism+pid+polinterest+selfmonitor+info_treatment+blm_treatment+j6_treatment,data=data)
m.cor.dnorm3.l <- lm(demnorm3_100~women_protest_pre+trans_protest_pre+othergender_protest_pre+black_protest_pre+hispanic_protest_pre+asian_protest_pre+otherrace_protest_pre+gay_protest_pre+othersexuality_protest_pre+conservative_protest_pre+liberal_protest_pre+otherideology_protest_pre+republican_protest_pre+democratic_protest_pre+otherparty_protest_pre+evangelical_protest_pre+jewish_protest_pre+muslim_protest_pre+atheist_protest_pre+otherreligion_protest_pre+urban_protest_pre+rural_protest_pre+union_protest_pre+poor_protest_pre+rich_protest_pre+degree_protest_pre+dropout_protest_pre+female+nonbinary+black+indigenous+asian+pacific+othrace+hispanic+inc_000+catholic+orthodox+mormon+jewish+muslim+buddhist+hindu+atheist+agnostic+othreligion+noreligion+evangelical_christian+age+suburban+townie+rural+othplace+conservatism+pid+polinterest+selfmonitor+info_treatment+blm_treatment+j6_treatment,data=data)
m.cor.dnorm4.l <- lm(demnorm4_100~women_protest_pre+trans_protest_pre+othergender_protest_pre+black_protest_pre+hispanic_protest_pre+asian_protest_pre+otherrace_protest_pre+gay_protest_pre+othersexuality_protest_pre+conservative_protest_pre+liberal_protest_pre+otherideology_protest_pre+republican_protest_pre+democratic_protest_pre+otherparty_protest_pre+evangelical_protest_pre+jewish_protest_pre+muslim_protest_pre+atheist_protest_pre+otherreligion_protest_pre+urban_protest_pre+rural_protest_pre+union_protest_pre+poor_protest_pre+rich_protest_pre+degree_protest_pre+dropout_protest_pre+female+nonbinary+black+indigenous+asian+pacific+othrace+hispanic+inc_000+catholic+orthodox+mormon+jewish+muslim+buddhist+hindu+atheist+agnostic+othreligion+noreligion+evangelical_christian+age+suburban+townie+rural+othplace+conservatism+pid+polinterest+selfmonitor+info_treatment+blm_treatment+j6_treatment,data=data)
m.cor.viol.l <- lm(polvol100~women_protest_pre+trans_protest_pre+othergender_protest_pre+black_protest_pre+hispanic_protest_pre+asian_protest_pre+otherrace_protest_pre+gay_protest_pre+othersexuality_protest_pre+conservative_protest_pre+liberal_protest_pre+otherideology_protest_pre+republican_protest_pre+democratic_protest_pre+otherparty_protest_pre+evangelical_protest_pre+jewish_protest_pre+muslim_protest_pre+atheist_protest_pre+otherreligion_protest_pre+urban_protest_pre+rural_protest_pre+union_protest_pre+poor_protest_pre+rich_protest_pre+degree_protest_pre+dropout_protest_pre+female+nonbinary+black+indigenous+asian+pacific+othrace+hispanic+inc_000+catholic+orthodox+mormon+jewish+muslim+buddhist+hindu+atheist+agnostic+othreligion+noreligion+evangelical_christian+age+suburban+townie+rural+othplace+conservatism+pid+polinterest+selfmonitor+info_treatment+blm_treatment+j6_treatment,data=data)
m.cor.viol1.l <- lm(polvol1_100~women_protest_pre+trans_protest_pre+othergender_protest_pre+black_protest_pre+hispanic_protest_pre+asian_protest_pre+otherrace_protest_pre+gay_protest_pre+othersexuality_protest_pre+conservative_protest_pre+liberal_protest_pre+otherideology_protest_pre+republican_protest_pre+democratic_protest_pre+otherparty_protest_pre+evangelical_protest_pre+jewish_protest_pre+muslim_protest_pre+atheist_protest_pre+otherreligion_protest_pre+urban_protest_pre+rural_protest_pre+union_protest_pre+poor_protest_pre+rich_protest_pre+degree_protest_pre+dropout_protest_pre+female+nonbinary+black+indigenous+asian+pacific+othrace+hispanic+inc_000+catholic+orthodox+mormon+jewish+muslim+buddhist+hindu+atheist+agnostic+othreligion+noreligion+evangelical_christian+age+suburban+townie+rural+othplace+conservatism+pid+polinterest+selfmonitor+info_treatment+blm_treatment+j6_treatment,data=data)
m.cor.viol2.l <- lm(polvol2_100~women_protest_pre+trans_protest_pre+othergender_protest_pre+black_protest_pre+hispanic_protest_pre+asian_protest_pre+otherrace_protest_pre+gay_protest_pre+othersexuality_protest_pre+conservative_protest_pre+liberal_protest_pre+otherideology_protest_pre+republican_protest_pre+democratic_protest_pre+otherparty_protest_pre+evangelical_protest_pre+jewish_protest_pre+muslim_protest_pre+atheist_protest_pre+otherreligion_protest_pre+urban_protest_pre+rural_protest_pre+union_protest_pre+poor_protest_pre+rich_protest_pre+degree_protest_pre+dropout_protest_pre+female+nonbinary+black+indigenous+asian+pacific+othrace+hispanic+inc_000+catholic+orthodox+mormon+jewish+muslim+buddhist+hindu+atheist+agnostic+othreligion+noreligion+evangelical_christian+age+suburban+townie+rural+othplace+conservatism+pid+polinterest+selfmonitor+info_treatment+blm_treatment+j6_treatment,data=data)
m.cor.viol3.l <- lm(polvol3_100~women_protest_pre+trans_protest_pre+othergender_protest_pre+black_protest_pre+hispanic_protest_pre+asian_protest_pre+otherrace_protest_pre+gay_protest_pre+othersexuality_protest_pre+conservative_protest_pre+liberal_protest_pre+otherideology_protest_pre+republican_protest_pre+democratic_protest_pre+otherparty_protest_pre+evangelical_protest_pre+jewish_protest_pre+muslim_protest_pre+atheist_protest_pre+otherreligion_protest_pre+urban_protest_pre+rural_protest_pre+union_protest_pre+poor_protest_pre+rich_protest_pre+degree_protest_pre+dropout_protest_pre+female+nonbinary+black+indigenous+asian+pacific+othrace+hispanic+inc_000+catholic+orthodox+mormon+jewish+muslim+buddhist+hindu+atheist+agnostic+othreligion+noreligion+evangelical_christian+age+suburban+townie+rural+othplace+conservatism+pid+polinterest+selfmonitor+info_treatment+blm_treatment+j6_treatment,data=data)
m.cor.viol4.l <- lm(polvol4_100~women_protest_pre+trans_protest_pre+othergender_protest_pre+black_protest_pre+hispanic_protest_pre+asian_protest_pre+otherrace_protest_pre+gay_protest_pre+othersexuality_protest_pre+conservative_protest_pre+liberal_protest_pre+otherideology_protest_pre+republican_protest_pre+democratic_protest_pre+otherparty_protest_pre+evangelical_protest_pre+jewish_protest_pre+muslim_protest_pre+atheist_protest_pre+otherreligion_protest_pre+urban_protest_pre+rural_protest_pre+union_protest_pre+poor_protest_pre+rich_protest_pre+degree_protest_pre+dropout_protest_pre+female+nonbinary+black+indigenous+asian+pacific+othrace+hispanic+inc_000+catholic+orthodox+mormon+jewish+muslim+buddhist+hindu+atheist+agnostic+othreligion+noreligion+evangelical_christian+age+suburban+townie+rural+othplace+conservatism+pid+polinterest+selfmonitor+info_treatment+blm_treatment+j6_treatment,data=data)
m.cor.viol5.l <- lm(polvol5_100~women_protest_pre+trans_protest_pre+othergender_protest_pre+black_protest_pre+hispanic_protest_pre+asian_protest_pre+otherrace_protest_pre+gay_protest_pre+othersexuality_protest_pre+conservative_protest_pre+liberal_protest_pre+otherideology_protest_pre+republican_protest_pre+democratic_protest_pre+otherparty_protest_pre+evangelical_protest_pre+jewish_protest_pre+muslim_protest_pre+atheist_protest_pre+otherreligion_protest_pre+urban_protest_pre+rural_protest_pre+union_protest_pre+poor_protest_pre+rich_protest_pre+degree_protest_pre+dropout_protest_pre+female+nonbinary+black+indigenous+asian+pacific+othrace+hispanic+inc_000+catholic+orthodox+mormon+jewish+muslim+buddhist+hindu+atheist+agnostic+othreligion+noreligion+evangelical_christian+age+suburban+townie+rural+othplace+conservatism+pid+polinterest+selfmonitor+info_treatment+blm_treatment+j6_treatment,data=data)
m.cor.viol6.l <- lm(polvol6_100~women_protest_pre+trans_protest_pre+othergender_protest_pre+black_protest_pre+hispanic_protest_pre+asian_protest_pre+otherrace_protest_pre+gay_protest_pre+othersexuality_protest_pre+conservative_protest_pre+liberal_protest_pre+otherideology_protest_pre+republican_protest_pre+democratic_protest_pre+otherparty_protest_pre+evangelical_protest_pre+jewish_protest_pre+muslim_protest_pre+atheist_protest_pre+otherreligion_protest_pre+urban_protest_pre+rural_protest_pre+union_protest_pre+poor_protest_pre+rich_protest_pre+degree_protest_pre+dropout_protest_pre+female+nonbinary+black+indigenous+asian+pacific+othrace+hispanic+inc_000+catholic+orthodox+mormon+jewish+muslim+buddhist+hindu+atheist+agnostic+othreligion+noreligion+evangelical_christian+age+suburban+townie+rural+othplace+conservatism+pid+polinterest+selfmonitor+info_treatment+blm_treatment+j6_treatment,data=data)
## Figure
plotdata.correlations <- data.frame(outcome=factor(c(rep("Protest",216),rep("Democratic Norms",135),rep("Political Violence",189)),levels=c("Protest","Democratic Norms","Political Violence")),
                                    grouptype=factor(c(rep(c("Gender","Gender","Gender","Race","Race","Race","Race","Sexuality","Sexuality","Ideology","Ideology","Ideology","Party","Party","Party","Religion","Religion","Religion","Religion","Religion","Place","Place","Union","Income","Income","Education","Education"),20)),levels=c("Ideology","Party","Race","Religion","Gender","Sexuality","Education","Income","Place","Union")),
                                    coef=c(m.rq2.post.l$coefficients[2:28],m.rq2.post.1.l$coefficients[2:28],m.rq2.post.2.l$coefficients[2:28],m.rq2.post.3.l$coefficients[2:28],m.rq2.post.4.l$coefficients[2:28],m.rq2.post.5.l$coefficients[2:28],m.rq2.post.6.l$coefficients[2:28],m.rq2.post.7.l$coefficients[2:28],m.cor.dnorm.l$coefficients[2:28],m.cor.dnorm1.l$coefficients[2:28],m.cor.dnorm2.l$coefficients[2:28],m.cor.dnorm3.l$coefficients[2:28],m.cor.dnorm4.l$coefficients[2:28],m.cor.viol.l$coefficients[2:28],m.cor.viol1.l$coefficients[2:28],m.cor.viol2.l$coefficients[2:28],m.cor.viol3.l$coefficients[2:28],m.cor.viol4.l$coefficients[2:28],m.cor.viol5.l$coefficients[2:28],m.cor.viol6.l$coefficients[2:28]))

p.correlations <- ggplot(plotdata.correlations,aes(x=coef,y=grouptype)) + geom_density_ridges(alpha=0.2,scale=0.8,fill="#0072B2") + theme_classic() +  geom_vline(xintercept=0,linetype="dashed",color="red") + facet_wrap(vars(outcome),ncol=3,nrow=1,scale="free_x") + xlab("Coefficient") + ylab("")
